<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="/css/common.css" />
		<link rel="stylesheet" type="text/css" href="/js/flatpickr.min.css" />
		<link rel="stylesheet" type="text/css" href="/bootstrap-3.3.7/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="/dialog/css/dialog.css" />
		<link rel="stylesheet" type="text/css" href="/css/font-awesome.css" />
	</head>

	<body>
		<!--顶部导航 -->
		<nav class="topNavItemBox">
			<div id="ItemBox">
				<div class="title">肉品溯源管理系统</div>
			</div>
		</nav>
		<!-- 左侧导航 -->
		<#include "left.ftl"/>
        <!--装卸货查询 -->

		<div class="page_main">
			<h3>装卸货管理</h3><span class="add_link"><a href="loadingAdd.ftl">新增装卸货信息></a></span>
			<div class="page_content">
				<h4>装卸货查询</h4>
				<br /><br />
				<form id="loadingQueryInfo_query" method="post" action="StevedoringAction_getStevedoringByCondition">
					<label>物流批次</label><input type="text" name="transitBatchID" class="commonInputtext" /><span></span>
					<label>装卸类型</label><select name="stevedoringType" class="commonSelect">
						<!-- <input type="text" name="stevedoringType" class="commonInputtext" /> -->
						
							<option value="">请选择装卸类型</option>
							<option value="1">装货</option>
							<option value="2">卸货</option>
						</select>						

					<br />
					<label>开始时间</label><input type="text" name="beginTime" id="start_date" class="commonInputtext" /><span></span>
					<label>结束时间</label><input type="text" name="endTime" id="end_date" class="commonInputtext" />
					<!--<label>按生产企业查询</label><input class="commonInputtext" type="text" name="" id="productId" />-->
					<input type="submit" value="查询" style="display: inline-block; margin-left: 50px;" />
				</form>
				<div>
					<table id="loadingQuery_table" class="table" width="100%">
						<thead>
							<tr>
								<th><input id="checkall" type="checkbox" /></th>
								<th width="100">物流批次</th>
								<th width="150">运输物品</th>
								<th width="100">装卸类型</th>
								<th width="100">装卸时间</th>
								<th width="120">运送开始时间</th>
								<th width="120">运送结束时间</th>
								<th width="120">货车车牌号</th>
								<th width="120">货车所属公司</th>
								<th width="100">装卸说明</th>
								<th width="120"></th>
							</tr>
						</thead>
						<tbody>
							<tr id="no_data">
								<td width="20"></td>
								<td width="100">暂无数据</td>

							</tr>
						</tbody>
					</table>
				</div>
				<input type="button" id="deleteAllchoice" value="删除所选" style="display: none;" />
				<div id="barcon" name="barcon" style="margin-left: 200px;font-size:10px"></div>

			</div>
			<div class="footer">
				<div class="footer_lineone">
					<span id="logo"></span>肉品溯源管理系统 
					<span class="footer_lineoneSpan"><a href="aboutus.html">关于我们</a></span>
					<span class="footer_lineoneSpan"><a target="_blank" href="http://www.cfsiw.com/">食品安全信息</a></span> 
					<span class="footer_lineoneSpan"><a href="suggestionAdd.ftl">联系我们</a></span>
				</div>
				<div class="footer_linetwo">
					 &copy;2017广东技术师范学院
				</div>
			</div>
		</div>

		<script src="js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/google-maps.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery.form.js"></script>
		<script src="dialog/js/dialog.js"></script>
		<script src="js/jquery.validate.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/messages_zh.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/common.js" type="text/javascript" charset="utf-8"></script>
		<script src="flatpickr/flatpickr.js">
		</script>
		<script type="text/javascript" charset="UTF-8">
			$(function() {
				//初始化侧边栏
				$(".vertical-nav").verticalnav({
					speed: 400,
					align: "left"
				});

				var re_data; //每次传过来的数据
				
				//时间控制器
				$("#start_date").flatpickr();
				$("#end_date").flatpickr();

				//表单校验
				$("#loadingQueryInfo_query").validate();
				//查询
				$("#loadingQueryInfo_query").ajaxForm(function(data) {
					console.log(data);
					re_data = data;
					$("#loadingQuery_table tbody tr").remove();
					for(var i = 0; i < data.length; i++) {
						var tb = $("#loadingQuery_table tbody");
						var td_head = '<tr id="loadingQuery_row' + data[i].stevedoringId + '">';
						var td1 = '<td><input type="checkbox" class="isCheck" value="' + data[i].stevedoringId + '"/></td>';
						var td2 = '<td>' + data[i].transitBatchID + '</td>';
						if(data[i].productType==2){
							var td3 = '<td>猪肉产品</td>';
						}else{
							var td3 = '<td>生猪</td>';
						}
						if(data[i].actionType==2){
							var td4 = '<td>卸货</td>';
						}else{
							var td4 = '<td>装货</td>';
						}
						
						var td5 = '<td>' + data[i].loadTime.replace("T"," ") + '</td>';
						var td6 = '<td>' + data[i].transitStartTime.slice(0,19) + '</td>';
						var td7 = '<td>' + data[i].transitEndTime.slice(0,19) + '</td>';
						var td8 = '<td>' + data[i].licenseNumber + '</td>';
						var td9 = '<td>' + data[i].compName + '</td>';
						var td10 = '<td>' + data[i].remark + '</td>';
						var td11 = '<td><input type="button" onclick="updateData(' + i + ')" class="change" value="更改" style="padding:0 5px"/><input type="button" value="删除" onclick="deleteData(' + data[i].stevedoringId + ')" style="padding:0 5px" /></td>'
						var tr_add = td_head + td1 + td2 + td3 + td4 + td5 + td6 + td7 + td8 + td9 + td10 +td11+ '</tr>';
						tb.append(tr_add);
					}
					$("#no_data").remove();
					$("#deleteAllchoice").css("display","block");
					goPage(1,4,"loadingQuery_table");
				});

				//多选
				$("#checkall").click(function() {
					$('input[class="isCheck"]').attr("checked", this.checked);
				});
				var $isCheck = $("input[class='isCheck']");
				$isCheck.click(function() {
					$("#checkall").attr("checked", $isCheck.length == $("input[class='isCheck']:checked").length ? true : false);
				});

				//删除

				function deleteByids(delete_data) {
					$.dialog({
						type: 'confirm',
						contentHtml: '<p style:"magrin:0 auto">确认删除？</p>',
						onClickOk: function() {
							$.ajax({
								url: "StevedoringAction_deleteStevedoring",
								data: {
									'selectRows': delete_data
								},
								error: function(XMLHttpRequest, textStatus, errorThrown) {
									//弹失败框
									$.dialog({
										type: 'info',
										contentHtml: '<img class="info-icon" src="dialog/images/icon/fail.png" alt="删除失败" /><p class="info-text">删除失败</p>',
										autoClose: 2000
									});
								},
								success: function() {
									//弹成功框
									$.dialog({
										type: 'info',
										contentHtml: '<img class="info-icon" src="dialog/images/icon/success.png" alt="删除成功" /><p class="info-text">删除成功</p>',
										autoClose: 2000
									});
									//删除相对应的行
									var chrstr = delete_data.split(",");
									console.log(chrstr);
									console.log($("#loadingQuery_row" + chrstr[0]));
									for(i = 0; i < chrstr.length; i++) {
										$("#loadingQuery_row" + chrstr[i]).remove();
									}
								}
							});
						}
					});

				}
				deleteData = function(i) {
					var st = i;
					st += ",";
					deleteByids(st);
				}
				$("#deleteAllchoice").click(function() {
					delete_data = get_checkbox_data();
					deleteByids(delete_data);
				});

				function get_checkbox_data() {
					var data_temp = "";
					$("input[class='isCheck']:checked").each(function() { // 遍历选中的checkbox
						data_temp += $(this).val() + ',';
						console.log(data_temp);
					});;
					return data_temp;
				}

				//更改
				updateData = function(i) {
					var row0 = '<form id="loadingQuery_updateform" action="StevedoringAction_updateStevedoring" method="post"><ul class="changePage500">'
					var row1 = '<li><label class="labelBeforinput">物流批次</label><input name="transitbatchInfo.transitBatchId" class="bigInputtext" readOnly="true" type="text" value="' + re_data[i].transitBatchID + '" /></li>';
					
				/* 	if(re_data[i].productType==2){//猪肉产品
						var row2 = '<li><label class="labelBeforinput">商品类型</label>'
						+'<input type="radio" checked name="productType" value="2" />猪肉产品 '
						+'<input type="radio" name="productType" value="1" />生猪 </li>';
					}else{
						var row2 = '<li><label class="labelBeforinput">商品类型</label>'
							+'<input type="radio" name="productType" value="2" />猪肉产品 '
							+'<input type="radio" checked name="productType" value="1" />生猪 </li>';
					} */
					var row2 = '<li><label class="labelBeforinput">商品类型</label><input type="radio" name="productType" value="2" checked/>猪肉产品</li>';
					if(re_data[i].actionType==1){//装卸货判断默认选值
						var row3 = '<li><label class="labelBeforinput">装卸类型</label><input type="radio" checked name="actionType" value="1" />装货<input type="radio" name="actionType" value="2" />卸货 </li>';
					}else{
						var row3 = '<li><label class="labelBeforinput">装卸类型</label><input type="radio" name="actionType" value="1" />装货 <input type="radio" checked name="actionType" value="2" />卸货 </li>';
					} 
					var row4 = '<li><label class="labelBeforinput">装卸时间</label><input name="loadTime" data-date-format="Y-m-d" id="loadTime" class="bigInputtext" require type="text" value="' + re_data[i].loadTime + '" /></li>';
					var row5 = '<li><label class="labelBeforinput">装卸说明</label><input name="remark"  class="bigInputtext" type="text" value="' + re_data[i].remark + '" /></li>';
					var row6 = '<input type="hidden" name="stevedoringId" value="' + re_data[i].stevedoringId + '" />';
					var row7 = '<input type="hidden" name="transitBatchID" value="' + re_data[i].transitBatchID + '" />';
					var row8 = '<input type="hidden" name="transitStartTime" value="' + re_data[i].transitStartTime + '" />';
					var row9 = '<input type="hidden" name="transitEndTime" value="' + re_data[i].transitEndTime + '" />';
					var row10 = '<input type="hidden" name="licenseNumber" value="' + re_data[i].licenseNumber + '" />';
					var row11 = '<input type="hidden" name="compName" value="' + re_data[i].compName + '" />';
					var row12 = '</form>'
					var str = row0 + row1 + row2 + row3 +row4 + row5 + row6 +row7+ row8 + row9 + row10 + row11+ row12;
					//console.log($("#loadingQuery_table"));

					$.dialog({
						type: 'confirm',
						titleText: '更改数据',
						contentHtml: str,
						onClickOk: function() {
							$("#loadingQuery_updateform").ajaxSubmit({
								type: 'post',
								error: function(XMLHttpRequest, textStatus, errorThrown) {
									//失败
									$.dialog({
										type: 'info',
										contentHtml: '<img class="info-icon" src="dialog/images/icon/fail.png" alt="更新失败" /><p class="info-text">更新失败</p>',
										autoClose: 2000
									});
								},
								success: function(data) {
									//成功弹窗
									$.dialog({
										type: 'info',
										contentHtml: '<img class="info-icon" src="dialog/images/icon/success.png" alt="更新成功" /><p class="info-text">更新成功</p>',
										autoClose: 2000
									});
									var row = $("#loadingQuery_row" + data.stevedoringInfor.stevedoringId);
									row.find("td").eq(1).text(data.stevedoringInfor.transitBatchID);
									if(data.stevedoringInfor.productType==2){
										row.find("td").eq(2).text("猪肉产品");
									}else{
										row.find("td").eq(2).text("生猪");
									}
									if(data.stevedoringInfor.actionType==1){
										row.find("td").eq(3).text("装货");
									}else{
										row.find("td").eq(3).text("卸货");
									}
									row.find("td").eq(4).text(data.stevedoringInfor.loadTime);
									row.find("td").eq(5).text(data.stevedoringInfor.transitStartTime);
									row.find("td").eq(6).text(data.stevedoringInfor.transitEndTime);
									row.find("td").eq(7).text(data.stevedoringInfor.licenseNumber);
									row.find("td").eq(8).text(data.stevedoringInfor.compName);
									row.find("td").eq(9).text(data.stevedoringInfor.remark);
									re_data[i] = data.stevedoringInfor;
								}

							});
						}

					});
					//时间控制器
					$("input[name='inspectTime']").flatpickr();
					$("#loadTime").flatpickr();
					//表单校验
					$("#loadingQuery_updateform").validate();
				}

			});
		</script>

	</body>

</html>